<template>
  <div class="index-container">
    <div class="main-header clearfix">
      <el-row>
       <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
          <div style="opacity: 0;">11</div>
          <!-- <el-button type="primary"  icon="el-icon-plus" class="sureBtn"  size="medium"  @click="handleAdd" > 添加疾病</el-button> -->
        </el-col>
        <el-col :xs="16" :sm="16" :md="16" :lg="16" :xl="16">
         <div class="search fr">
             <div>
               <el-input  v-model="searchForm.name" size="medium"  placeholder="老人姓名"></el-input>
             </div>
             <div>
               <el-input  v-model="searchForm.id_card" size="medium"  placeholder="身份证号"></el-input>
             </div>
             <el-button size="medium" type="primary" icon="el-icon-search"  class="fr" @click="handleSearch" > 搜索</el-button>
          </div>
        </el-col>
      </el-row>
    </div>
    <div class="main-content" style="height: calc(100vh - 250px);">
      <main-table
        :columns="tableColumns"
        :data="tableList"
        :loading="loading"
        :pagination="pagination"
        @getData="fetchTableList"
        wrapperHeight="calc(100% - 73px)" height="100%"
      >
       <el-table-column slot="action" fixed="right" label="操作" width="250">
         <template slot-scope="scope">
           <el-button size="mini" type="success" @click="edit(scope.row)">查看</el-button>
           <el-button size="mini" type="danger" @click="cancelOrder(scope.row)">删除</el-button>
         </template>
       </el-table-column>
      </main-table>
    </div>


    <el-dialog
      title="就诊记录信息"
      :visible.sync="dialogVisible"
      :close-on-click-modal="false"
      width="800px">
      <visit-older-info v-if="dialogVisible" @cancle="dialogVisible = false" :data="ruleForm"></visit-older-info>
    </el-dialog>

  </div>
</template>
<script>
  import mainTable from "@/components/main-table/index";
  import * as APIMedicalCareDisease from '@/api/medicalCareDisease';
  import { age, unixToDate } from "@/utils";
  import visitOlderInfo from './components/visit-older-info';
  export default {
    name: "medicine-disease3-visit-older",
    components: {
      mainTable,
      visitOlderInfo
    },
    data() {
      return {
        loading: false,
        title: '添加图标',
        dialogVisible: false,
        ruleForm: {},
        searchForm: {
           page: 1
        },
        tableList:[],
        pagination: {
          current: 1,
          size: 10,
          total: 0
        },
        tableColumns: [
         {
           index: true,
           fixed: true
         },
         {
           prop: 'name',
           label: '姓名',
         },
         {
           prop: 'sex',
           label: '性别',
           formatter (row, column, cellValue) {
             if(cellValue == 1){
               return '男';
             } else if(cellValue == 2){
               return '女';
             }
           }
         },
         {
           prop: 'age',
           label: '年龄'
         },
         {
           prop: 'id_card',
           label: '身份证号'
         },
         {
           prop: 'doc_name',
           label: '医师'
         },
         {
           prop: 'time',
           label: '就诊时间',
           width: 190,
           formatter (row, column, cellValue) {
             if(cellValue){
               return unixToDate(cellValue)
             }
           }
         },
         {
           prop: 'create_time',
           label: '添加时间',
           width: 190,
           formatter (row, column, cellValue) {
             return unixToDate(cellValue)
           }
         },
         {
           slot: 'action'
         }
        ],
        key: Math.random(),
      };
    },
    created() {},
    beforeDestroy() {},
    mounted() {
      this.fetchTableList();
    },
    methods: {
      load () {
        this.fetchTableList()
      },
      // 手动清空/搜索
      clear () {
        this.fetchTableList({ page: 1 })
      },
      handleSearch() {
        this.pagination = {
          current: 1,
          size: 10,
          total: 0
        }
        this.fetchTableList({ page: 1 })
      },
      fetchTableList(pageObj) {
        this.loading = true
        this.searchForm = {
          ...this.searchForm,
          ...pageObj
        }
        APIMedicalCareDisease.jiuzhenmanOlder(this.searchForm).then((resp) => {
          if (resp.code == 200) {
            const { list = [], total = 0 } = resp.data;
            this.tableList = list || []
            this.pagination.total = total;
          }
        }).finally(() => {
         this.loading = false
        });
      },
      edit (row) {
        this.title = '编辑药品入库';
        this.key = Math.random();
        this.ruleForm = { ...row };
        this.dialogVisible = true
      },
      handleAdd() {
        this.title = '添加疾病';
        this.dialogVisible = true;
        this.key = Math.random();
        this.ruleForm = { name:'', sort: 1 };
      },
      cancelOrder(row) {
        this.$confirm("确定删除该条数据, 是否继续?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            APIMedicalCareDisease.jiuzhenmanDeleteall({ id_card: row.id_card }).then((resp) => {
              if (resp.code === 200) {
                this.$message({ type: "success", message: "删除成功!"});
                this.fetchTableList();
              }
            });
          })
          .catch(() => {
          });
      },
    },
  };
</script>
<style lang="scss" scoped>
  .index-container {
    box-sizing: border-box;
    width: 100%;
    padding: 0 30px !important;
    margin: 0 !important;
    background: #fff !important;

    .main-header {
      padding-top: 4px;
      margin-bottom: 24px;

      .search {
        display: inline-block;

        .search-title {
          flex: 0 0 48px;
          width: 48px;
          font-size: 16px;
          line-height: 36px;
          color: #333;
        }
      }

      .search > div {
        display: inline-block;
        margin-left: 20px;
      }
    }
    .task-icon-img{
      width: 80px;
      height: 80px;
    }
  }

  .form-footer {
    padding-left: 100px;
  }

  .dialog-main {
    .table-do {
      margin-bottom: 15px;
    }

    ::v-deep {
      th {
        .cell {
          color: #fff;
        }
      }
    }
  }
</style>
